<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
	<meta http-equiv="pragma" content="no-cache" />
	<link rel="stylesheet" href="/css/style.css" type="text/css"/>
	<script type="text/javascript" src="/js/jquery.js"></script>
	<script type="text/javascript" src="/js/util.js"></script>
</head>
<script type="text/javascript">
//////////////////////////////////////////////////////////////////////
////  email = "wenpin.qian@happyelements.com"                     ////
////  team = "Athene"                                             ////
////  warnings = "This is generated page,Do Not Modify!";         ////
////  tips = "Opera & IE not supported|Chrome & Safari sugguested"////
//////////////////////////////////////////////////////////////////////
window.returnValue=0;
var taskId = null;
var gettaskUrl = "/task/get/";
var edittaskUrl = "/task/edit/";
var currenttask = null;
$(document).ready(function() {
	taskId = window.dialogArguments;
	$.ajax({
		   type: "GET",
		   url: gettaskUrl,
		   data: "taskId=" + taskId,
		   dataType: "json",
		   success: function(data) {
			   if(data.code > 0) {
				   var result = data.result;
				   $("#taskId").val(result.taskId);
				   $("#deployId").val(result.deployId);
				   $("#name").val(result.name);
				   $("#desc").val(result.desc);
				   $("#level").val(result.level);
				   $("#catalog").val(result.catalog);
				   $("#type").val(result.type);
				   $("#dests").val(result.dests);
				   $("#compaignId").val(result.compaignId);
				   $("#postTaskId").val(result.postTaskId);
				   $("#startTalk").val(result.startTalk);
				   $("#endTalk").val(result.endTalk);
				   $("#deduct").val(result.deduct);
				   $("#reward").val(result.reward);
				   				   
				   currenttask = result; 
				   listselectors();
				   window.returnValue=1;
			   }else {
				   errDialog(data.message);
			   }
		   }
	});
});

function listselectors() {
}

function edittask() {
	var taskIdParam = "taskId=" + taskId;
	var nameValue = $("#name").val();
	if(!checkString("名字",nameValue,false)) {
		return;
	}
	var nameParam = "name=" + xparseString(nameValue);
		
	var descValue = $("#desc").val();
	if(!checkString("描述",descValue,false)) {
		return;
	}
	var descParam = "desc=" + xparseString(descValue);
		
	var levelValue = $("#level").val();
	if(!checkInteger("任务难度",levelValue,false)) {
		return;
	}
	var levelParam = "level=" + xparseInt(levelValue);
		
	var catalogValue = $("#catalog").val();
	
	var catalogParam = "catalog=" + catalogValue;
		
	var typeValue = $("#type").val();
	
	var typeParam = "type=" + typeValue;
		
	var destsValue = $("#dests").val();
	
	var destsParam = "dests=" + destsValue;
		
	var compaignIdValue = $("#compaignId").val();
	if(!checkInteger("战役ID",compaignIdValue,false)) {
		return;
	}
	var compaignIdParam = "compaignId=" + xparseInt(compaignIdValue);
		
	var postTaskIdValue = $("#postTaskId").val();
	if(!checkInteger("后继任务",postTaskIdValue,false)) {
		return;
	}
	var postTaskIdParam = "postTaskId=" + xparseInt(postTaskIdValue);
		
	var startTalkValue = $("#startTalk").val();
	
	var startTalkParam = "startTalk=" + startTalkValue;
		
	var endTalkValue = $("#endTalk").val();
	
	var endTalkParam = "endTalk=" + endTalkValue;
		
	var deductValue = $("#deduct").val();
	
	var deductParam = "deduct=" + deductValue;
		
	var rewardValue = $("#reward").val();
	
	var rewardParam = "reward=" + rewardValue;
			
	$.ajax({
		   type: "POST",
		   url: edittaskUrl,
		   		   data:  taskIdParam + '&' +  nameParam  +'&'+   descParam  +'&'+   levelParam  +'&'+   catalogParam  +'&'+   typeParam  +'&'+   destsParam  +'&'+   compaignIdParam  +'&'+   postTaskIdParam  +'&'+   startTalkParam  +'&'+   endTalkParam  +'&'+   deductParam  +'&'+   rewardParam  ,
		   dataType: "json",
		   success: function(data) {
			   if(data.code > 0) {
			   	   beforeWindowClose();
				   window.close();
			   }else {
				   errDialog(data.message);
			   }
		   }
	});
}

	
	
	
	
	
			function adddests() {
			var destsstr = $("#dests").val();
			var returnCallback = function(retvalue) {
				$('#dests').val(retvalue);
			}
			openDialog("/pages/core/Array.html",["/pages/customer/ConditionEntity.html",destsstr],"dialogWidth:600px;dialogHeight:600px;status:no;help:no;center:yes",returnCallback);
		}
	
	
	
			function addstartTalk() {
			var startTalkstr = $("#startTalk").val();
			var returnCallback = function(retvalue) {
				$('#startTalk').val(retvalue);
			}
			openDialog("/pages/core/Array.html",["/pages/customer/TaskTalk.html",startTalkstr],"dialogWidth:600px;dialogHeight:600px;status:no;help:no;center:yes",returnCallback);
		}
	
			function addendTalk() {
			var endTalkstr = $("#endTalk").val();
			var returnCallback = function(retvalue) {
				$('#endTalk').val(retvalue);
			}
			openDialog("/pages/core/Array.html",["/pages/customer/TaskTalk.html",endTalkstr],"dialogWidth:600px;dialogHeight:600px;status:no;help:no;center:yes",returnCallback);
		}
	
			function adddeduct() {
			var deductstr = $('#deduct').val();
			var returnCallback = function(retvalue) {
				$('#deduct').val(retvalue);
			}
			openDialog("/pages/customer/RewardEntity.html",deductstr,"dialogWidth:600px;dialogHeight:600px;status:no;help:no;center:yes",returnCallback);
		}
	
			function addreward() {
			var rewardstr = $('#reward').val();
			var returnCallback = function(retvalue) {
				$('#reward').val(retvalue);
			}
			openDialog("/pages/customer/RewardEntity.html",rewardstr,"dialogWidth:600px;dialogHeight:600px;status:no;help:no;center:yes",returnCallback);
		}
	
function openResource(fieldname,dependfield) {
	var param = "";
	if(dependfield!="") {
		param = $("#" + dependfield).val()
		if(param == null || param == "") {
			alert("你先把【" + $("#lbl_" + dependfield).html() + "】填了再上传");
			return;
		}
	}
	resourceDialog("task",$("#" + fieldname).val(),param,function(result) {
		if(result != undefined && result != "") {
			$("#" + fieldname).val(result);
		}
	});
}

function beforeWindowClose() {
	if(window.returnCallback) {
		window.returnCallback(window.returnValue);
	}
	window.onbeforeunload = null;
	return true;
}

</script>
<body onunload="beforeWindowClose()">
	<div class="addarea">
	<form action="/task/add" method="post">
		<table>
			<tbody>
				<tr>
					<td>ID</td><td><input type="text" id="taskId" name="taskId" disabled/></td>
					<td>发布Id</td><td><input type="text" id="deployId" name="deployId" disabled/></td>
				</tr>
			</tbody>
		</table>
		<table>
			<tbody>				
					<tr>					<td>
						<label for="name" id="lbl_name">名字</label>
													<input type="text" id="name" name="name" /><span class="tips">[文字]</span>
											</td>
									
										<td>
						<label for="desc" id="lbl_desc">描述</label>
													<input type="text" id="desc" name="desc" /><span class="tips">[文字]</span>
											</td>
					</tr>				
					<tr>					<td>
						<label for="level" id="lbl_level">任务难度</label>
													<input type="text" id="level" name="level" /><span class="tips">[整数]</span>
											</td>
									
										<td>
						<label for="catalog" id="lbl_catalog">任务大类</label>
																				<select id="catalog" name="catalog">
								
									<option value="1">新手</option>
								
									<option value="2">成长</option>
								
									<option value="3">战役</option>
								
									<option value="4">日常</option>
								
									<option value="5">临时</option>
															</select>
											</td>
					</tr>				
					<tr>					<td>
						<label for="type" id="lbl_type">任务类型</label>
																				<select id="type" name="type">
								
									<option value="1">功能</option>
								
									<option value="2">打怪</option>
								
									<option value="3">升级</option>
								
									<option value="4">成就</option>
								
									<option value="5">物品</option>
								
									<option value="6">收集</option>
								
									<option value="7">制作</option>
								
									<option value="8">商城</option>
								
									<option value="9">战斗</option>
								
									<option value="10">邀请好友</option>
								
									<option value="11">访问好友</option>
								
									<option value="12">发送free gift</option>
								
									<option value="13">收到free gift</option>
															</select>
											</td>
									
										<td>
						<label for="dests" id="lbl_dests">完成条件</label>
													<input type="text" id="dests" name="dests" value="[]" disabled/>
							<input type="button" value="..." onclick="adddests()"/>
											</td>
					</tr>				
					<tr>					<td>
						<label for="compaignId" id="lbl_compaignId">战役ID</label>
													<input type="text" id="compaignId" name="compaignId" /><span class="tips">[整数]</span>
											</td>
									
										<td>
						<label for="postTaskId" id="lbl_postTaskId">后继任务</label>
													<input type="text" id="postTaskId" name="postTaskId" /><span class="tips">[整数]</span>
											</td>
					</tr>				
					<tr>					<td>
						<label for="startTalk" id="lbl_startTalk">任务前对话</label>
													<input type="text" id="startTalk" name="startTalk" value="[]" disabled/>
							<input type="button" value="..." onclick="addstartTalk()"/>
											</td>
									
										<td>
						<label for="endTalk" id="lbl_endTalk">任务后对话</label>
													<input type="text" id="endTalk" name="endTalk" value="[]" disabled/>
							<input type="button" value="..." onclick="addendTalk()"/>
											</td>
					</tr>				
					<tr>					<td>
						<label for="deduct" id="lbl_deduct">任务消耗</label>
													<input type="text" id="deduct" name="deduct" value="{}" disabled/>
							<input type="button" value="..." onclick="adddeduct()"/>
											</td>
									
										<td>
						<label for="reward" id="lbl_reward">奖励</label>
													<input type="text" id="reward" name="reward" value="{}" disabled/>
							<input type="button" value="..." onclick="addreward()"/>
											</td>
					</tr>							</tbody>
		</table>
		<input type="button" onclick="edittask()" value="修改"/>
	</form>
	</div>
</body>